<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="et">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Mäo elektriarvesite näitude haldamise infosüsteem</title>
		<!--
		<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
		<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
		<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
		<link rel="stylesheet" href="/resources/demos/style.css" />
		<script>
			$(function() 
			{
				$( "#datepicker" ).datepicker();
			});
		</script>
		-->
		
		<link rel="stylesheet" href="/MaoArvestiteNaitudeHaldamiseInfosysteem/static/css/ui/1.10.3/themes/smoothness/jquery-ui.css" />
		<script src="/MaoArvestiteNaitudeHaldamiseInfosysteem/static/js/jquery-1.9.1.js"></script>
		<script src="/MaoArvestiteNaitudeHaldamiseInfosysteem/static/js/ui/1.10.3/jquery-ui.js"></script>
		<script type="text/javascript" src="static/js/myJsMethods.js"></script>
		<link rel="stylesheet" href="/MaoArvestiteNaitudeHaldamiseInfosysteem/static/css/style.css" />
		<script>
			$(function() 
			{
				$( ".datepicker" ).datepicker();
			});
			  
			
			$(document).ready(function () 
			{
				fetchDataByID("/MaoArvestiteNaitudeHaldamiseInfosysteem/AJAXServices", showParentMeterLatestReadingsWhenInsertingLocalTerritoryElectricityMeterAfterAjaxSuccess, "getElectricityMeterLastReadings", $('#insertLocalTerritoryElectricityMeterParentElectricityMeter').val(), "#neidOnNaguniiRohkemStPoleVahetMisSiiaKirjutab");
				
				
				$("input").blur(function()
				{
					//Saan inputi id nime, millel sisestust tehti
					var inputIDOfParentMeterLatestReading = $(this).attr("id");
					
					//divi class nimi, mis säilitab eelmist lugemit on sama nimega, mis inputi id, saan seega tema väärtuse
					//lähtudes klassi nimedele viitamisest jqueryga s.t. div.klassinimi
					var latestReading = Number($("div." + inputIDOfParentMeterLatestReading).text().replace(/[^0-9\.\-]+/g,""));
					var insertedReading = Number($("#" + inputIDOfParentMeterLatestReading).val().replace(/[^0-9\.\-]+/g,""));
					if (latestReading > insertedReading)
					{
						alert("Palun kontrollige, et olete veendunud, et tahtsite sisestada näitu, mis on eelmisest väiksem?\n" + 
								 "Seda tõlgendatakse, nagu oleks arvesti mõõdikul ring täis saanud!");
					}
				    
				});
				
			});
		</script>
		
		<style>	
			table
			{
				font-family: verdana,arial,sans-serif;
				font-size:11px;
				color:#333333;
				border-width: 1px;
				border-color: #666666;
				border-collapse: collapse;
			}
			
			th {
			    border-width: 1px;
				padding: 8px;
				border-style: solid;
				border-color: #666666;
				background-color: #dedede;
			}
			td {
				border-width: 1px;
				padding: 8px;
				border-style: solid;
				border-color: #666666;
				background-color: #ffffff;
			}
			
		</style>
	</head>
	<body>
		<p>Siseterritooriumi alamarvesti lisamine</p>
		
		ARVESTEID LISADES, ei tohi ülemarvestiks saada valida arvestit, millel on juba leping mingi ettevõtte ja elektripaketiga
		<!-- not empty variable tähendab, et pole ei null, ega ka tühi string (või tühi list vms) -->
		<c:if test="${not empty insertingLocalTerritoryElectricityMeterToADatabaseWasUnsuccessful}">
			<p style="color:red;">
				<c:out value="${insertingLocalTerritoryElectricityMeterToADatabaseWasUnsuccessful}" />
			</p>
		</c:if>
		<div id="insertLocalTerritoryElectricityMeterFormDiv">
			<%@ include file="forms/insertLocalTerritoryElectricityMeterForm.jsp" %>
		</div>
	</body>
</html>